package com.wave.wavesystem.serve.aop;

import cn.dev33.satoken.stp.StpUtil;
import com.wave.common.enums.ErrorCode;
import com.wave.common.exception.WaveException;
import com.wave.wavesystem.serve.annotation.LoginCheck;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoginCheckAop {

    @Around("@annotation(loginCheck)")
    public Object checkPermission(ProceedingJoinPoint joinPoint, LoginCheck loginCheck) throws Throwable {
        boolean login = StpUtil.isLogin();
        if (!login) {
            throw new WaveException(ErrorCode.NOT_LOGIN);
        }
        return joinPoint.proceed();
    }


}
